<?php
session_start();

if(preg_match('/localhost/', curPageURL())){
	include_once("constant_local.php");
}else{
	//production...
	include_once("constant.php");
}
$detechBrowser=new DetechBrowser();
$detechBrowser->init();

function checkCurrentPath($path){
	//LV3
	//$path="/path/" not "path"
	if(preg_match($path, curPageURL())){
		return true;
	}else{
		return false;
	}
}

function loadCSSFile($file){
	if(LOADFILE_DEBUG==false){
		?>
		<style type="text/css">
			<?php echo file_get_contents($file);?>
		</style>
		<?php
	}else{
		?>
		<link rel="stylesheet" href="<?php echo $file;?>" />
		<?php
	}
}

function loadJSFile($file){
	if(LOADFILE_DEBUG==false){
		?>
		<script>
			<?php echo file_get_contents($file);?>
		</script>
		<?php
	}else{
		?>
		<script src="<?php echo $file;?>"></script>
		<?php
	}
}

function loadImage($imgpath){
	//LV1
	global $detechBrowser;
	$img=NOT_FOUND_IMAGE;
	
	if((!$detechBrowser->msie)&&(LOADIMAGE_DEBUG==false) ){
		
		if(hasFile($imgpath)){
			$img=$homepage = file_get_contents($imgpath);
			$img=base64_encode($img); 
		}else{
			$img=file_get_contents($img);
			$img=base64_encode($img);
		}
		return "data:image/gif;base64,".$img;
	}else{
		if(hasFile($imgpath)){
			return $imgpath;	
		}else{
			return $img;	
		}
	}
}
function hasFile($imgpath){
	//LV2		
	//for local file
		if(file_exists($imgpath)){
			return true;	
		}
	//for file in internet
		$AgetHeaders = @get_headers($imgpath);
		if (preg_match("|200|", $AgetHeaders[0])) {
			// file exists
			return true;
		}
		return false;
	
}

function __autoload($classname){
	global $folder;
	foreach($folder as $f){
		if(file_exists(FS_PATH.$f."/".$classname.".class.php")){
			include_once(FS_PATH.$f."/".$classname.".class.php");
		}
	}	
}

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>